﻿using System.Collections.Generic;
using ProxyTool.Models;
using ProxyTool.Utils;

namespace ProxyTool.Services
{
    /// <summary>
    ///     系统服务
    /// </summary>
    public static class SystemService
    {
        /// <summary>
        ///     WSS系统服务地址
        /// </summary>
        public const string SystemSvcURI = @"/wss/System.svc";

        /// <summary>
        ///     测试连接
        /// </summary>
        public static bool TestConnection(string u9URI)
        {
            if (string.IsNullOrWhiteSpace(u9URI))
                throw new ProxyToolException("U9(C)地址 不能为空，请检查配置");
            string systemServiceURI = u9URI + SystemSvcURI;
            const string serviceAction = "TestConnection";
            const string serviceActionName = "测试连接";
            return ServiceHelper.DoRequest<bool>(systemServiceURI, serviceAction, serviceActionName);
        }

        /// <summary>
        ///     获取所有企业列表
        /// </summary>
        public static List<EnterpriseData> GetEnterprises(string u9URI)
        {
            if (string.IsNullOrWhiteSpace(u9URI))
                throw new ProxyToolException("U9(C)地址 不能为空，请检查配置");
            string systemServiceURI = u9URI + SystemSvcURI;
            const string serviceAction = "GetEnterprises";
            const string serviceActionName = "获取所有企业";
            return ServiceHelper.DoRequest<List<EnterpriseData>>(systemServiceURI, serviceAction, serviceActionName);
        }

        /// <summary>
        ///     获取语言列表
        /// </summary>
        public static List<LanguageData> GetLanguages(string u9URI, string enterpriseID)
        {
            if (string.IsNullOrWhiteSpace(u9URI))
                throw new ProxyToolException("U9(C)地址 不能为空，请检查配置");
            string systemServiceURI = u9URI + SystemSvcURI;
            const string serviceAction = "GetLanguages";
            const string serviceActionName = "获取语言列表";
            Dictionary<string, object> postData = new Dictionary<string, object>();
            postData.Add("enterpriseID", enterpriseID);
            return ServiceHelper.DoRequest<List<LanguageData>>(systemServiceURI, serviceAction, serviceActionName,
                postData);
        }

        /// <summary>
        ///     获取用户组织列表
        /// </summary>
        public static List<OrgData> GetOrgsByUserCode(string u9URI, string enterpriseID, string userCode,
            string culture)
        {
            if (string.IsNullOrWhiteSpace(u9URI))
                throw new ProxyToolException("U9(C)地址 不能为空，请检查配置");
            string systemServiceURI = u9URI + SystemSvcURI;
            const string serviceAction = "GetOrgsByUserCode";
            const string serviceActionName = "获取用户组织列表";
            Dictionary<string, object> postData = new Dictionary<string, object>();
            postData.Add("enterpriseID", enterpriseID);
            postData.Add("userCode", userCode);
            postData.Add("culture", culture);
            return ServiceHelper.DoRequest<List<OrgData>>(systemServiceURI, serviceAction, serviceActionName, postData);
        }
    }
}